Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.default = void 0;

var _util2 = _interopRequireDefault(require("../../public/utils/util")), _config = _interopRequireDefault(require("../../utils/config")), _util3 = _interopRequireDefault(require("../../utils/util")), _radarUtil = require("../../utils/radar-util");

function _interopRequireDefault(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

function _defineProperty(e, t, i) {
    return t in e ? Object.defineProperty(e, t, {
        value: i,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : e[t] = i, e;
}

function _classCallCheck(e, t) {
    if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function");
}

function _defineProperties(e, t) {
    for (var i = 0; i < t.length; i++) {
        var a = t[i];
        a.enumerable = a.enumerable || !1, a.configurable = !0, "value" in a && (a.writable = !0), 
        Object.defineProperty(e, a.key, a);
    }
}

function _createClass(e, t, i) {
    return t && _defineProperties(e.prototype, t), i && _defineProperties(e, i), e;
}

var appData = getApp().globalData, EditorContentManager = function() {
    function i(e) {
        var t = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : {};
        _classCallCheck(this, i), Object.assign(this, {
            options: t
        }), this.page = e, this.swiper = [], this.windowWidth = appData.systemInfo.windowWidth, 
        this.__init();
    }
    return _createClass(i, [ {
        key: "__init",
        value: function() {
            this.options.data && this.__initData(), this.__methods();
        }
    }, {
        key: "__initData",
        value: function() {
            var e = this.options.scope || "editorContent", t = this.options.data;
            if (this._data = {}, !_util2.default.isEmptyObject(t)) for (var i in t) t.hasOwnProperty(i) && "function" != typeof t[i] && (this._data[i] = t[i]);
            this.page.setData(_defineProperty({}, "".concat(e), this._data));
        }
    }, {
        key: "__methods",
        value: function() {
            this.page.$$ecPreviewImage = this.$$ecPreviewImage.bind(this), this.page.$$redirectToDetail = this.$$redirectToDetail.bind(this), 
            this.page.openLocation = this.openLocation.bind(this), this.page.onSelectNav = this.onSelectNav.bind(this), 
            this.page.viewBargaining = this.viewBargaining.bind(this), this.page.imageLoad = this.imageLoad.bind(this), 
            this.page.playVideo = this.playVideo.bind(this), this.page.onVideoFullChange = this.onVideoFullChange.bind(this), 
            this.page.onVideoEnd = this.onVideoEnd.bind(this);
        }
    }, {
        key: "$$ecPreviewImage",
        value: function(e) {
            var t = e.currentTarget.dataset, i = t.url, a = t.ci, n = this.page.data[this.options.scope].content[a].data.images.map(function(e) {
                return e.url;
            });
            (0, _radarUtil.radarRecord)(_radarUtil.RADAR_TYPES.TIMEPICTURE), wx.previewImage({
                current: i,
                urls: n
            });
        }
    }, {
        key: "$$redirectToDetail",
        value: function(e) {
            var t = e.currentTarget.dataset, i = t.key, a = t.index, n = this.page.data[this.options.scope].content[i].data.lists[a];
            this.reportAnalytics(n);
            var o = _util3.default.getSiteModelPUrl(n);
            o && this.navigateSite(o);
        }
    }, {
        key: "reportAnalytics",
        value: function(e) {
            var t = e.modid;
            _config.default.model.forEach(function(e) {
                t === e.modid && getApp().reportAnalytics("card_site_".concat(e.modtemplate, "_tap"));
            });
        }
    }, {
        key: "openLocation",
        value: function(e) {
            var t = e.currentTarget.dataset;
            wx.facility("openLocation", {
                latitude: t.latitude,
                longitude: t.longitude,
                name: t.name,
                address: t.address
            });
        }
    }, {
        key: "onSelectNav",
        value: function(e) {
            var r = this, t = e.currentTarget.dataset, i = t.key, a = t.type, n = this.page.data[this.options.scope].content[i].data, d = n.navList, s = n.modid;
            if ("model" === a) {
                var o = function(e) {
                    var t = d[e], i = t.sid, a = t.navid, n = t.catid, o = _util3.default.createModelUrl(_config.default.model, {
                        sid: i,
                        modid: s,
                        navid: a,
                        catid: n
                    });
                    r.navigateSite(o);
                };
                if (1 < d.length) this.page.selectComponent("#actionSheet").show(d.map(function(e) {
                    return {
                        text: e.title,
                        onClick: o
                    };
                })); else o(0);
            } else this.navigateSite("/miniweb/pages/common/bargaining/list/list");
        }
    }, {
        key: "viewBargaining",
        value: function(e) {
            var t = e.currentTarget.dataset, i = t.id, a = t.index;
            this.navigateSite("/miniweb/pages/common/bargaining/view/view?index=".concat(a, "&bargainid=").concat(i));
        }
    }, {
        key: "navigateSite",
        value: function(e) {
            var t = this.page.data.card;
            e += "".concat(e.includes("?") ? "&" : "?", "sid=").concat(t.sid, "&source=").concat(_config.default.WX_APP_NAME, "&fromuid=").concat(t.uid, "&cardid=").concat(t.cardid, "&guid=").concat(t.guid), 
            wx.navigateTo({
                url: e
            }), getApp().recordCount(t.cardid, "site");
        }
    }, {
        key: "$$formatSwiperHeight",
        value: function(e) {
            var t = this.options.scope, i = this.windowWidth, a = this.swiper, n = e.index;
            if (!a.includes(n)) {
                a.push(n);
                var o = i * (e.imageHeight / e.imageWidth);
                this.page.setData(_defineProperty({}, "".concat(t, ".content[").concat(n, "].height"), o));
            }
        }
    }, {
        key: "imageLoad",
        value: function(e) {
            var t = e.detail.width, i = e.detail.height, a = e.currentTarget.dataset.index;
            this.$$formatSwiperHeight({
                imageWidth: t,
                imageHeight: i,
                index: a
            });
        }
    }, {
        key: "playVideo",
        value: function(e) {
            var t = this, i = e.currentTarget.dataset.url;
            this.page.$report("card_view_tap_video"), this.page.$setData({
                videoUrl: i,
                showVideoModal: !0
            }, function() {
                t.videoCtx || (t.videoCtx = wx.createVideoContext("video")), (0, _radarUtil.radarRecord)(_radarUtil.RADAR_TYPES.WATCHVIDEO), 
                t.videoCtx.play(), t.videoCtx.requestFullScreen({
                    direction: 0
                }), t.videoCtx.showStatusBar && t.videoCtx.showStatusBar();
            });
        }
    }, {
        key: "onVideoFullChange",
        value: function(e) {
            if (!e.detail.fullScreen) {
                var t = this.page.data.card;
                t && (0, _radarUtil.radarPush)(t, _radarUtil.RADAR_TYPES.WATCHVIDEO), this.videoCtx.stop();
            }
        }
    }, {
        key: "onVideoEnd",
        value: function() {
            this.videoCtx.exitFullScreen(), this.videoCtx.stop();
        }
    } ]), i;
}(), _default = EditorContentManager;

exports.default = _default;